package org.tigris.atlas.examples.messages;

import java.util.Locale;

import org.tigris.atlas.examples.form.ValidationExampleForm;
import org.tigris.atlas.messages.MessageUtils;

import junit.framework.TestCase;

public class TestMessageResources extends TestCase {

	public void testGetMessage() {
		String message = MessageUtils.getSummaryMessage("hello", null, ValidationExampleForm.class);
		assertNotNull(message);
	}
	
	public void testSummaryAndDetailIdentical() {
		String summary = MessageUtils.getSummaryMessage("hello.world", null, ValidationExampleForm.class);
		String detail = MessageUtils.getDetailMessage("hello.world", null, ValidationExampleForm.class);
		
		assertNotNull(summary);
		assertNotNull(detail);
		assertEquals(summary, detail);
	}
	
	public void testSummaryAndDetailDifferent() {
		String summary = MessageUtils.getSummaryMessage("hello", null, ValidationExampleForm.class);
		String detail = MessageUtils.getDetailMessage("hello", null, ValidationExampleForm.class);
		
		assertNotNull(summary);
		assertNotNull(detail);
		assertFalse(summary.equals(detail));
	}
	
	public void testInternationalization() {
		String summaryDefault = MessageUtils.getSummaryMessage("hello.i18n", null, ValidationExampleForm.class);
		String summaryFrench = MessageUtils.getSummaryMessage("hello.i18n", null, ValidationExampleForm.class, Locale.FRANCE);
		String summarySpanish = MessageUtils.getSummaryMessage("hello.i18n", null, ValidationExampleForm.class, new Locale("es"));
		
		assertNotNull(summaryDefault);
		assertNotNull(summaryFrench);
		assertNotNull(summarySpanish);
		
		assertEquals(summaryDefault, summaryFrench);
		assertFalse(summaryDefault.equals(summarySpanish));
	}
	
}
